<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/3/19
 * Time: 16:33
 */

namespace Biz\model\trade;


class ShopCourier extends \Doraemon\pockets\datebase\BaseDbModel
{
    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_trade';

    const _DATABASE_ = 'shop_trade';

    const _TABLE_NAME = 'shop_courier';

    const STATUS_NORMAL = 1;

    //需要配送的物流编号范围
    const NEED_DELIVERY_ID_RANGE = 100;

    //自营门店自提使用的编号
    const SELF_LIFTING_ID = 150;
    const SELF_LIFTING_NAME = "门店自提";

    public static function getCourier($field, $map)
    {

        $list = self::get($field, $map);

        if (empty($list)) {
            return [];
        }

        return $list;
    }

    public static function getCourierList($fields, $where = [])
    {

        $list = self::select($fields, $where);
        if (!$list) {
            return [];
        }

        return $list;
    }

    public static function getCourierName($courierCode)
    {
        return self::get('courier_name', ['courier_code' => $courierCode]);
    }

    public static function add($data)
    {
        return self::insert($data)->rowCount();
    }

    public static function updateById($id)
    {
        return self::update(['courier_website' => ''],['courier_id' => $id]);
    }

    /**
     * @param array $ids
     * @return array
     */
    public static function getByCourierIds(array $ids): array
    {
        if ($ids) {
            $map = [
                'courier_id' => $ids,
            ];
            return self::select('*', $map);
        } else {
            return [];
        }

    }
}